//
// Created by XiaoXiu on 2025/5/20.
//


#ifndef UTIL_H
#define UTIL_H
#include <stdint.h>
#include <stdbool.h>
#include <winsock2.h>
#include "snake.h"
#include "snakeio.h"

uint64_t getUnixTimestampMillis();

void strCopy(const char *src, char *dest, const size_t destSize);

void generateRandomString(char *dest, size_t length);

const char *directionToStr(Direction dir);

Direction strToDirection(const char *str);

PacketType strToPacketType(const char *str);

const char *packetTypeToStr(PacketType type);

bool is_frame_packet(const Packet *pkt);

//配置
extern int MAX_PLAYERS;
extern int GRID_SIZE;
extern int CELL_SIZE;
extern int DELTA_TIME;
extern int MOVE_INTERVAL;
extern int WINDOW_WIDTH;
extern int WINDOW_HEIGHT;
extern int SNAKE_CAPACITY;
extern char playerName[17];
extern bool running;
extern bool inited;
extern bool syncing;
extern Food food;
extern Player *localPlayer;
extern SOCKET sockFD;
extern PacketRingBuffer rb;
extern HANDLE netIOThread;
extern int cTick;
extern int sTick;
extern Packet *frameBuffer[1024];
extern const int delayFrames;
extern int score;
extern int playerCount;
extern char localPlayerId[64];
extern volatile bool socketThreadRunning;
extern int tickCounter;
extern int syncCounter;
#endif //UTIL_H
